/*
 * GameAreaCoordinate.java
 *
 * Created on January 11, 2007, 2:18 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package net.sf.iSnake.core;
import java.io.Serializable;

/**
 *
 * @author thelinuxmaniac
 */
public class GameAreaCoordinate implements Serializable,Cloneable   {
    
    private Short x;
    private Short y;
    
    /** Creates a new instance of GameAreaCoordinate */
    public GameAreaCoordinate() {
        this.x = 0;
        this.y = 0;
    }

    public GameAreaCoordinate(GameAreaCoordinate gac) {
        this.x = gac.getX();
        this.y = gac.getY();
    }

    public GameAreaCoordinate clone() throws CloneNotSupportedException {
        GameAreaCoordinate coordinate = (GameAreaCoordinate) super.clone();
        return coordinate;
    }

    public GameAreaCoordinate(Short x,Short y) {
        this.x = x;
        this.y = y;
    }
    
    public GameAreaCoordinate(Integer x,Integer y)
    {
        this.x = x.shortValue();
        this.y = y.shortValue();
    }

    public Short getX() {
        return x;
    }

    public void setX(Short x) {
        this.x = x;
    }
    
    public void setX(short x)   {
        this.x = new Short(x);
    }

    public Short getY() {
        return y;
    }

    public void setY(Short y) {
        this.y = y;
    }
    
    public void setY(short y)   {
        this.y = new Short(y);
    }
    
    public void set(Short x,Short y)
    {
        this.x = x;
        this.y = y;
    }
    
    public void set(GameAreaCoordinate gac)
    {
        this.x = gac.getX();
        this.y = gac.getY();
    }
    
    /**
     * to increment the x and y coordinate by dx & dy
     * @param dx small change that is to be made to x coordinate
     * @param dy small change that is to be made to y coordinate
     */
    public void makeSmallChange(short dx,short dy)
    {
        this.setX(new Integer(this.getX().shortValue()+dx).shortValue());
        this.setY(new Integer(this.getY().shortValue()+dy).shortValue());
    }
    
    public String toString()  {
        return "[x="+x.toString()+", y="+y.toString()+"]";
    }

    public boolean equals(Object obj) {
        GameAreaCoordinate c = (GameAreaCoordinate) obj;
        if( ( this.getX().equals(c.getX()) ) && (this.getY().equals(c.getY())))
            return true;
        else
            return false;
    }
    
    /**
     * Transforms the Game Area Coordinate into the absolute floating point coordinate which is used for drawing shapes
     */
    
    public float getXCoordinateInPixel()
    {
        /*
         * Illustration:
         * if x = 1, the this function returns 1*10 as each block in Game Area is 10x10 pixel wide
         * Max value that can be returned is 640 pixel
         */
        //System.out.println("x="+x+" returned= "+(float) (getX()*10));
        return (float) (getX()*10);
    }
    public float getYCoordinateInPixel()
    {
        /*
         * Illustration:
         * if y = 3, the this function returns 3*10 as each block in Game Area is 10x10 pixel wide
         * Max value that can be returned is 480 pixel
         */
        return (float) (getY()*10);
    }
}